// ==================== 通用类型 ====================

export interface ApiResponse<T = any> {
  success: boolean
  message: string
  data: T
}

export interface PaginationParams {
  page: number
  size: number
}

export interface PaginationResponse<T> {
  records: T[]
  total: number
  current: number
  size: number
  pages: number
}

// ==================== 管理员相关类型 ====================

export interface AdminInfo {
  id: number
  username: string
  nickname: string
  avatar?: string
  role: string
  lastLoginTime?: string
  createTime: string
}

export interface LoginForm {
  username: string
  password: string
}

// ==================== 用户相关类型 ====================

export interface User {
  id: number
  openid: string
  nickname: string
  avatar?: string
  phone?: string
  credits: number
  totalCreditsEarned: number
  totalCreditsConsumed: number
  isVip: boolean
  vipExpireTime?: string
  registerTime: string
  lastLoginTime?: string
  status: 'active' | 'banned'
  creditsUpdatedTime?: string
}

export interface UserSearchParams extends PaginationParams {
  userId?: string
  nickname?: string
  vipStatus?: string
  status?: string
}

export interface UserCreditsForm {
  type: 'add' | 'subtract' | 'set'
  amount: number
  reason: string
}

// ==================== 积分相关类型 ====================

export interface CreditsStats {
  totalCredits: number
  totalConsumed: number
  totalOrders: number
  totalRevenue: number
}

export interface CreditsPackage {
  id: number
  name: string
  creditsAmount: number
  price: number
  originalPrice?: number
  isPopular: boolean
  discountLabel?: string
  validityDays: number
  status: 0 | 1
  sortOrder: number
  createTime: string
  updateTime: string
}

export interface CreditsPackageForm {
  id?: number
  name: string
  creditsAmount: number
  price: number
  originalPrice?: number
  isPopular: boolean
  discountLabel?: string
  validityDays: number
  status: 0 | 1
}

export interface CreditsTransaction {
  id: string
  userId: number
  transactionType: 'purchase' | 'consume' | 'earn' | 'refund'
  sourceType: string
  sourceId?: string
  amount: number
  balanceBefore: number
  balanceAfter: number
  description: string
  status: 'pending' | 'completed' | 'failed'
  createTime: string
  updateTime: string
}

export interface CreditsTransactionSearchParams extends PaginationParams {
  userId?: string
  transactionType?: string
  sourceType?: string
  startTime?: string
  endTime?: string
}

export interface CreditsConsumptionConfig {
  id: number
  type: string
  name: string
  cost: number
  unit: string
  description: string
  icon?: string
  status: 0 | 1
  createTime: string
  updateTime: string
}

// ==================== 订单相关类型 ====================

export interface OrderStats {
  totalOrders: number
  paidOrders: number
  pendingOrders: number
  totalAmount: number
}

export interface Order {
  id: number
  orderNo: string
  userId: number
  orderType: 'credits' | 'vip'
  productName: string
  amount: number
  paidAmount?: number
  paymentMethod: 'wechat' | 'alipay'
  status: 'pending' | 'paid' | 'cancelled' | 'refunded'
  thirdPartyOrderNo?: string
  transactionId?: string
  createTime: string
  paidTime?: string
  remark?: string
}

export interface OrderSearchParams extends PaginationParams {
  orderNo?: string
  userId?: string
  orderType?: string
  status?: string
  startTime?: string
  endTime?: string
}

// ==================== VIP相关类型 ====================

export interface VipStats {
  totalVipUsers: number
  activeVipUsers: number
  expiringSoonUsers: number
  vipRevenue: number
}

export interface VipUser {
  id: number
  userId: number
  nickname: string
  avatar?: string
  vipType: string
  startTime: string
  expireTime: string
  status: 'active' | 'expired' | 'cancelled'
  createTime: string
}

export interface VipSearchParams extends PaginationParams {
  userId?: string
  nickname?: string
  vipType?: string
  status?: string
}

// ==================== AI生图相关类型 ====================

export interface AiImageStats {
  totalImages: number
  todayImages: number
  successRate: number
  avgGenerateTime: number
}

export interface AiImageUsage {
  id: string
  userId: number
  prompt: string
  style?: string
  size?: string
  status: 'pending' | 'generating' | 'completed' | 'failed'
  imageUrls?: string[]
  creditsConsumed: number
  generateTime?: number
  createTime: string
  completeTime?: string
  errorMessage?: string
}

export interface AiImageSearchParams extends PaginationParams {
  userId?: string
  status?: string
  startTime?: string
  endTime?: string
}

// ==================== 系统相关类型 ====================

export interface SystemStats {
  totalUsers: number
  todayNewUsers: number
  totalRevenue: number
  todayRevenue: number
  serverStatus: 'online' | 'offline' | 'warning'
  diskUsage: number
  memoryUsage: number
  cpuUsage: number
}

export interface OperationLog {
  id: string
  adminId: number
  adminName: string
  operation: string
  module: string
  description: string
  ip: string
  userAgent: string
  createTime: string
}

export interface LogSearchParams extends PaginationParams {
  adminId?: string
  module?: string
  operation?: string
  startTime?: string
  endTime?: string
}

// ==================== 表格相关类型 ====================

export interface TableColumn {
  prop: string
  label: string
  width?: string | number
  minWidth?: string | number
  fixed?: 'left' | 'right'
  sortable?: boolean | 'custom'
  align?: 'left' | 'center' | 'right'
}

export interface SortParams {
  prop: string
  order: 'ascending' | 'descending'
}

// ==================== 表单相关类型 ====================

export interface FormRule {
  required?: boolean
  message: string
  trigger: 'blur' | 'change'
  min?: number
  max?: number
  type?: 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'array' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email'
  validator?: (rule: any, value: any, callback: any) => void
}

export interface FormRules {
  [key: string]: FormRule[]
}

// ==================== 图表相关类型 ====================

export interface ChartData {
  name: string
  value: number
}

export interface LineChartData {
  categories: string[]
  series: {
    name: string
    data: number[]
  }[]
}

export interface PieChartData {
  name: string
  value: number
}[]

// ==================== 菜单相关类型 ====================

export interface MenuItem {
  path: string
  name: string
  meta?: {
    title: string
    icon?: string
    hideInMenu?: boolean
    requiresAuth?: boolean
  }
  children?: MenuItem[]
}

export default {}
